--[[
	Project name: 3friends ENGiNE
	Module name: Event's library
	Authors/Contributors: V0ID
]]--

--Object array
	local e = {}
	e.__index = e
	e.array = {}

	
--Functions
function e.addHandler(eventname, func)
	if eventname and func and eventname ~= nil and func ~= nil then	--Check if values are exist
		table.insert(e.array,{event = eventname, fnct = func})
			return true
	else
		return false
	end
end

function e.removeHandler(eventname, func)
	if eventname and func and eventname ~= nil and func ~= nil then
		for k,v in ipairs(e.array) do
			if v.event == eventname and v.fnct == func then
				table.remove(e.array,k)
					return true
			end
		end
				return false	--Item not found in the table (function's runing to return's)
			else
				return false
	end
end

function e.callEvent(eventname, arg1, arg2, arg3, arg4)	--Use this function in callback
	if eventname and arg1 and arg2 and arg3 and arg4 then
			for k, v in ipairs(e.array) do
				if v.event == eventname then
					v.func(arg1, arg2, arg3, arg4)
				end
			end
	end
end

--End ;0